clear all
set type double
version 16.1

/* bids */
use ../tmp/sample_090122.dta, clear
cap mkdir ../tables
keep if after < .

gen reserve_mil = reserve / 1000000

label var reserve_mil "\raisebox{-2.2mm}[0mm][0mm]{Reserve}"
label var win_bid_pct "\raisebox{-2.2mm}[0mm][0mm]{WinBid / Reserve}"
label var percent_reserve "\raisebox{-2.2mm}[0mm][0mm]{Bid / Reserve}"
label var pt_tech "\raisebox{-2.2mm}[0mm][0mm]{Quality}"
label var ftt_ts1s "\raisebox{-2.2mm}[0mm][0mm]{t-value (Score)}"
label var ftt_ts1p "\raisebox{-2.2mm}[0mm][0mm]{t-value (Price)}"
label var nb "\raisebox{-2.2mm}[0mm][0mm]{Number of Bidders}"


cap drop theauction
bys id: egen theauction = max(firm_treatment)
estpost sum reserve_mil win_bid_pct percent_reserve pt_tech nb if winner == 1 & theauction == 1 & MDYbid > td(01apr2015) & MDYbid < td(01apr2018) & pt_tech < .
est store bid_treatment_before
estpost sum reserve_mil win_bid_pct percent_reserve pt_tech nb if winner == 1 & theauction == 1 & after == 1 & pt_tech < .
est store bid_treatment_after

cap drop theauction
bys id: egen theauction = min(firm_treatment)
estpost sum reserve_mil win_bid_pct percent_reserve pt_tech nb if winner == 1 & theauction == 1 & MDYbid > td(01apr2015) & MDYbid < td(01apr2018) & pt_tech < .
est store bid_control_before
estpost sum reserve_mil win_bid_pct percent_reserve pt_tech nb if winner == 1 & theauction == 1 & after == 1 & pt_tech < .
est store bid_control_after
/* note  & pt_tech < . is added on 23Aug23*/

estout bid_treatment_before bid_control_before /*bid_treatment_after bid_control_after*/  ///
using ../tables/summary_stats_auctions.tex, ///
		cells("mean(fmt(%09.3fc)) a(v())" ///
		"sd(par fmt(%9.3fc)) .") label replace collabels(none) ///
		stats(N, labels("\$N\$") fmt(%8.0gc)) style(tex) mlabels(,none)	
/*
estout treatment control using ../tables/summary_stats_firms.tex, ///
		cells("mean(fmt(%09.2fc)) a(v()) " ///
		"sd(par fmt(%9.2fc)) .") label replace collabels(none) style(tex) ///
			mlabels(,none) stats(N, labels("\$N\$") fmt(%8.0gc))
*/